/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : RhymingWordFamilyHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 1, 2008       Raghu Sarraff			       Created
 */
package lwf.handler.english;

import java.util.List;

import net.lwf.handler.util.ImageHtml;

import lwf.factory.PropertyReader;

/**
 * Type the class description here
 *  
 */
public class RhymingWordFamilyHandler {
	
	private String wordfamily = null;
	private String displayTable = null;

	public RhymingWordFamilyHandler(String _wordfamily) {
		this.wordfamily = _wordfamily;
		List lstRwords = (List)PropertyReader.getInstance().getRhymingWords().get(wordfamily);
		this.generateDisplayTable(lstRwords);
	}
	
	public String getDisplayTable() {
		return displayTable;
	}
	
	private void generateDisplayTable(List lstRwords) {
		StringBuffer sbQBlock = new StringBuffer();
		sbQBlock.append("<table border=\"0\"  width=\"75%\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\">");
			sbQBlock.append("<tr>");
				sbQBlock.append("<td width=\"75%\" class=\"tableHeaderBig\" nowrap>");
					sbQBlock.append( this.wordfamily + " - word family");
				sbQBlock.append("</td>");
			sbQBlock.append("</tr>");			
			sbQBlock.append("<tr>");
				sbQBlock.append("<td width=\"75%\"> &nbsp; </td>");
		    sbQBlock.append("</tr>");
        	sbQBlock.append("<tr>");
   				sbQBlock.append("<td width=\"75%\" class=\"data\" nowrap>");		    
					sbQBlock.append("<table  width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\">");
					boolean countdisplay = false;
					int nCounter = 0;
					int nDataCount = 0;
			        while(!countdisplay) {
			        	sbQBlock.append("<tr>");
				        	for(int i=0; i<2; i++) {
			        		    if(nDataCount<lstRwords.size() && !countdisplay ) {
			        		    	//WordInfo winfo = (WordInfo)lstRwords.get(nDataCount);
			        		    	String word = (String)lstRwords.get(nDataCount);
			        		    	sbQBlock.append("<td  width=\"15%\" class=\"datacenter\">");
			        		    		sbQBlock.append(word);
			        		    	sbQBlock.append("</td>");
			        		    	sbQBlock.append("<td width=\"10%\"> &nbsp; </td>");
			        		    	sbQBlock.append("<td width=\"15%\" >");
			        		    		sbQBlock.append(ImageHtml.getWordImage(word));
		        		    	    sbQBlock.append("</td>");
		        		    	    sbQBlock.append("<td width=\"10%\"> &nbsp; </td>");
			        		    }
			        		    else {
			        		    	sbQBlock.append("<td width=\"50%\" colspan=\"4\" >");
			        		    		sbQBlock.append("&nbsp;");
			        		    	sbQBlock.append("</td>");
			        		    	countdisplay = true;
			        		    }
			        		    nDataCount++;
				        	}
			        	sbQBlock.append("</tr>");
			        	if(nDataCount<lstRwords.size()) {
				        	sbQBlock.append("<tr>");
				        		sbQBlock.append("<td colspan=\"8\"> <hr> </td>");
				        	sbQBlock.append("</tr>");
			        	}
			        }
			        sbQBlock.append("</table>");
	       		sbQBlock.append("</td>");
		    sbQBlock.append("</tr>");
        sbQBlock.append("</table>");
        
		this.displayTable = sbQBlock.toString();	
	}

} //RhymingWordFamilyHandler

